Skip to content

Conversation

@suj-krishnan
Copy link

@suj-krishnan suj-krishnan commented Nov 26, 2025

This PR has the following changes towards fixing cockroachdb/cockroach#157774. Wherever applicable, it assumes the same semantics as the grpc metadata package.

@suj-krishnan suj-krishnan marked this pull request as draft November 26, 2025 09:13
@shubhamdhama
Copy link

I understand the PR is in draft, but I thought to leave some comments before go further

Support for lowercase-only keys in metadata. This is mandated by grpc due to requirements imposed by HTTP/2, and is not really needed in drpc but is being added for backward compatibility.

Is there any use case in cockroach where we need this? If not, I think we should avoid it.

@shubhamdhama shubhamdhama self-requested a review November 26, 2025 16:33
Comment on lines 157 to 167
// NewOutgoingContext attaches new metadata onto an outgoing context and returns
// the context. Same as NewIncomingContext for now,
// as we don't have separate keys for incoming and outgoing metadata.
// Will be fixed as part https://github.com/cockroachdb/cockroach/issues/156444
func NewOutgoingContext(ctx context.Context,
metadata map[string]string) context.Context {
newMetadata := make(map[string]string)
for k, v := range metadata {
newMetadata[strings.ToLower(k)] = v
}
return context.WithValue(ctx, metadataKey{}, newMetadata)
Copy link

@shubhamdhama shubhamdhama Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change should go in a separate PR. And how much effort would be to separate the keys and close the referenced issue since we are at it.

Copy link
Author

@suj-krishnan suj-krishnan Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating keys is not in the scope of these changes and it's not clear at this point if I'd take them up, but I'd prefer to add this method here with a note that it is WIP, since it helps keep the semantics in the dependent calling code clear. I have another draft PR with the changes in the calling code which I will share soon.

@suj-krishnan
Copy link
Author

I understand the PR is in draft, but I thought to leave some comments before go further

Support for lowercase-only keys in metadata. This is mandated by grpc due to requirements imposed by HTTP/2, and is not really needed in drpc but is being added for backward compatibility.

Is there any use case in cockroach where we need this? If not, I think we should avoid it.

Agreed! This PR is in draft because some of the changes in here are provisional (including this one). I'm working on the side to establish that no existing use-case would be broken due to this issue and will update the PR accordingly.

@suj-krishnan
Copy link
Author

suj-krishnan commented Nov 27, 2025

I understand the PR is in draft, but I thought to leave some comments before go further

Thanks for the early feedback 👍

…d other helper methods

This change has the following features:
- Support for lowercase-only keys in metadata. This is mandated by grpc due to
  requirements imposed by HTTP/2, and is not really needed in drpc but is being
  added for backward compatibility.
- Helper method FastFromIncomingContext for fast metadata retrieval, similar to the
  one in fast_metadata.go (cockroach repo).
- NewIncomingContext and NewOutgoingContext to create context with new metadata.
  They are both the same for now, as we don't have separate keys for incoming and
  outgoing metadata in drpc. However, adding them would help with clarity in
  the calling code. The implementation for these can be fixed as part of
  as part cockroachdb/cockroach#156444
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants